package com.xuan.chatroom.controller;


import com.xuan.chatroom.constants.Constant;
import com.xuan.chatroom.model.Message;
import com.xuan.chatroom.model.Result;
import com.xuan.chatroom.model.User;
import com.xuan.chatroom.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/message")
public class MessageController {
    @Autowired
    private MessageService messageService;


    @RequestMapping("/getMessages")
    public Result getHistoryMessageBySessionId(Integer sessionId) {     // 该 sessionId 是消息会话的id
        log.info("[sessionId]:" + sessionId);
        if (sessionId == null) return Result.success(new ArrayList<>());

        // 根据会话id 获取历史消息
        List<Message> messageList = messageService.getHistoryMessageBySessionId(sessionId);
        return Result.success(messageList);
    }
}
